Imports lookup
Imports System.Data

Partial Class WebForms_CInfo_Cor
    Inherits WebFormCommon

    Dim strPath As String

    Private Sub SetPageSecurity()
        Dim sec As New Secure
        Dim cfunc As New CIMSfunc

        sec.ParentPage = ParentPage

        sec.SetPageAccess(Session("UserName"))

        If ViewState("mode") = "view" Then
            cfunc.FormDisable(divMain)
        End If

        cfunc = Nothing
        sec = Nothing

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Select Case PageControlMode
            Case ControlMode.NewBusiness
                strPath = "New_Business"
            Case ControlMode.ClientServicing
                strPath = "Client_Servicing"
        End Select

        If Not Page.IsPostBack Then
            Dim lookup As New FillLookUp

            With lookup
                .FillDropDown(Country_cmb, FillLookUp.eLookUpType.country)
                .FillDropDown(City_cmb, FillLookUp.eLookUpType.country_city, , Country_cmb.SelectedValue.ToString)
                .FillDropDown(Status_cmb, FillLookUp.eLookUpType.other, "POLICY_STATUS")
            End With

            lookup = Nothing

            Call InitVars()

            Policy_td.InnerText = ViewState("PolicyNo")
            Provider_td.InnerText = ViewState("Provider")
            Name_td.InnerText = ViewState("CName")
            Call SetPageSecurity()
            Call LoadCorresInfo()

            Dim sec As New Secure

            sec.ParentPage = ParentPage

            If IsNothing(ViewState("CID")) Then
                sec.AddControl(Save_btn, Secure.ControlTypes.AddType)
            Else
                sec.AddControl(Save_btn, Secure.ControlTypes.EditType)
            End If

            sec.SetPageAccess(Session("UserName"))
            sec = Nothing
        End If
    End Sub

    Private Sub LoadCorresInfo()
        Dim vo As New DAOMain.POLICY_CLIENT_CORRES_VO
        Dim dao As New DAOMain.POLICY_CLIENT_CORRES_DAO
        Dim LookUp As New LookUp.FillLookUp

        vo.POLICY_SEQ_CD = ViewState("Seq_CD")
        vo.POLICY_CLIENT_CD = ViewState("CID")

        Dim dtSearch As DataTable = dao.Search(vo)

        If dtSearch.Rows.Count > 0 Then
            With dtSearch.Rows(0)
                Zip_txt.Text = .Item("ZIP_CD")

                Add1_txt.Text = .Item("CORRES_ADDRESS")
                Add2_txt.Text = .Item("CORRES_ADDRESS2")
                Status_cmb.SelectedValue = .Item("CORRES_ST")

                Country_cmb.SelectedValue = .Item("COUNTRY_CD")
                LookUp.FillDropDown(City_cmb, FillLookUp.eLookUpType.country_city, , Country_cmb.SelectedValue.ToString)

                City_cmb.SelectedValue = .Item("CITY_CD")
            End With
        End If

        LookUp = Nothing
        vo = Nothing
        dao = Nothing
    End Sub

    Protected Sub Save_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save_btn.Click
        Dim vo As New DAOMain.POLICY_CLIENT_CORRES_VO
        Dim dao As New DAOMain.POLICY_CLIENT_CORRES_DAO
        Dim polyfunc As New PolyFunc.ASPFunc

        vo.POLICY_SEQ_CD = ViewState("Seq_CD")
        vo.POLICY_CLIENT_CD = ViewState("CID")

        Dim dtSearch As DataTable = dao.Search(vo)

        With vo

            .ZIP_CD = Zip_txt.Text
            .CITY_CD = City_cmb.SelectedValue.ToString
            .CORRES_ADDRESS = Add1_txt.Text
            .CORRES_ADDRESS2 = Add2_txt.Text
            .CORRES_ST = Status_cmb.SelectedValue.ToString
            .COUNTRY_CD = Country_cmb.SelectedValue.ToString

            If dtSearch.Rows.Count > 0 Then
                .POLICY_CORRES_LAST_UPD_BY = Session("UserName")
                .POLICY_CORRES_LAST_UPD_DT = Now

                If dao.Update(vo) Then
                    polyfunc.MessageAlert(ParentPage, "Record Saved!")
                Else
                    polyfunc.MessageAlert(ParentPage, "Error Saving Record!")
                End If
            Else
                .POLICY_CORRES_CREA_BY = Session("UserName")
                .POLICY_CORRES_CREA_DT = Now

                If dao.Create_Record(vo) Then
                    polyfunc.MessageAlert(ParentPage, "Record Saved!")
                Else
                    polyfunc.MessageAlert(ParentPage, "Error Saving Record!")
                End If
            End If
        End With

        polyfunc = Nothing
        vo = Nothing
        dao = Nothing
    End Sub

    Protected Sub Country_cmb_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Country_cmb.SelectedIndexChanged
        Dim lookup As New LookUp.FillLookUp

        lookup.FillDropDown(City_cmb, FillLookUp.eLookUpType.country_city, , Country_cmb.SelectedValue.ToString)
        lookup = Nothing
    End Sub

    Protected Sub Main_Info_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Main_Info_btn.Click, Cancel_btn.Click
        Call InitSessions()
        Response.Redirect("~/" & strPath & "/Add_CInfo.aspx")
    End Sub

    Protected Sub Other_Info_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Other_Info_btn.Click
        Call InitSessions()
        Response.Redirect("~/" & strPath & "/Add_CInfo_Other.aspx")
    End Sub

    Protected Sub Risk_Profile_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Risk_Profile_btn.Click
        InitSessions()
        Response.Redirect("~/" & strPath & "/Add_CInfo_Risk.aspx")
    End Sub

    Protected Sub Attachments_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Attachments_btn.Click
        InitSessions()
        Response.Redirect("~/" & strPath & "/Add_CInfo_Att.aspx")
    End Sub

    Protected Sub Same_lbtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Same_lbtn.Click
        Dim dao As New DAOMain.POLICY_CLIENT_DTL_DAO_MAIN
        Dim vo As New DAOMain.POLICY_CLIENT_DTL_VO_MAIN
        Dim LookUp As New LookUp.FillLookUp

        With vo
            .POLICY_SEQ_CD = ViewState("Seq_CD")
            .POLICY_CLIENT_CD = ViewState("CID")

            Dim dtSearch As DataTable = dao.Search(vo)

            If dtSearch.Rows.Count > 0 Then
                With dtSearch.Rows(0)
                    Zip_txt.Text = .Item("ZIP_CD")

                    Add1_txt.Text = .Item("POLICY_CLIENT_ADDRESS")
                    Add2_txt.Text = .Item("POLICY_CLIENT_ADDRESS2")

                    Country_cmb.SelectedValue = .Item("COUNTRY_CD")
                    LookUp.FillDropDown(City_cmb, FillLookUp.eLookUpType.country_city, , Country_cmb.SelectedValue.ToString)

                    City_cmb.SelectedValue = .Item("CITY_CD")
                End With
            End If
        End With

        LookUp = Nothing
        dao = Nothing
        vo = Nothing
    End Sub
End Class
